<template>
  <view>
    <topBar title="添加车辆" />
    <view class="bg">
      <carNumber @changeKeyword="changeKeyword"></carNumber>
    </view>
    <button @click="handleAdd">确认</button>
  </view>
</template>

<script setup>
// 引入你封装的请求方法
import { apiPostCarAdd } from "@/api/car";
import topBar from "../../component/topbar.vue";
import carNumber from "../../component/carNumber.vue";
import { ref } from "vue";
//1.调用车辆管理列表接口
//2.拿到数据渲染到页面上
//3.如果没有，就显示新增
// const token = uni.getStorageSync("token");
// const handleAdd = () => {
//   uni.request({
//     url: "https://qwscrm.com:9202/car/v1/add",
//     method: "POST",
//     header: { Authorization: `Bearer ${token}` },
//     data: {
//       parkNo: plate.value,
//     },
//     success: (res) => {
//       if (res.statusCode === 200) {
//         // 请求成功后跳转到车辆管理页面
//         uni.reLaunch({
//           url: "/pages/carManager/carManager",
//         });
//       }
//     },
//   });
// };
const handleAdd =async () => {
 const res =await apiPostCarAdd({parkNo:plate.value})
console.log('添加车辆结果');
 console.log(res);
 
  if (res.code === 0) {
        // 请求成功后跳转到车辆管理页面
        uni.reLaunch({
          url: "/pages/carManager/carManager",
        });
      }
};
//接收车牌值
const plate = ref("苏");
const changeKeyword = (val) => {
  plate.value += val;
  console.log(plate.value);
};
</script>

<style lang="less">
.bg {
  box-shadow: 0rpx 0rpx 60rpx 0rpx rgba(250, 139, 63, 0.2);
  border-radius: 4rpx;
  margin: 15rpx;
  padding-bottom: 60rpx;
  width: 100%;
}
button {
  width: 686rpx;
  height: 96rpx;
  background: #0680fe;
  border-radius: 100rpx;
  margin: 0 32rpx;
  margin-top: 112rpx;
  font-family: "Source Han Sans CN, Source Han Sans CN";
  font-weight: bold;
  font-size: 36rpx;
  color: #ffffff;
  line-height: 96rpx;
  text-align: center;
  font-style: normal;
  text-transform: none;
}
</style>
